<%--
  Created by IntelliJ IDEA.
  User: zhuya
  Date: 2016/2/2
  Time: 16:45
  办事咨询 我的咨询
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=utf-8" language="java" %>
<%@ page language="java" import="com.oceansoft.mobile.econsole.modules.sys.entity.SysUser"%>
<%@ page language="java" import="com.oceansoft.mobile.econsole.common.constant.Constant"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="privilege" uri="/WEB-INF/privilege.tld" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>我的咨询</title>
  <meta charset='UTF-8'>
  <meta content="yes" name="apple-mobile-web-app-capable" />
  <meta content="black" name="apple-mobile-web-app-status-bar-style" />
  <meta content="telephone=no,email=no" name="format-detection" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui" />
  <link href="<c:url value='/resource/bszx/alipay/alipay.css'/>" type="text/css" rel="stylesheet" />
  <link href="<c:url value='/resource/bszx/alipay/amui-demo_files/toast.css'/>" type="text/css" rel="stylesheet" />
  <link href="<c:url value='/resource/bszx/alipay/button.css'/>"  type="text/css" rel="stylesheet" />
  <link href="<c:url value='/resource/bszx/alipay/amui-demo_files/dialog.css'/>" type="text/css" rel="stylesheet" />
  <link href="<c:url value='/resource/bszx/alipay/amui-demo_files/button-group.css'/>" type="text/css" rel="stylesheet" />
  <link href="<c:url value='/resource/bszx/alipay/amui-demo_files/card.css'/>" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="<c:url value='/resource/ueditor/third-party/jquery-1.10.2.min.js'/>"></script>
  <script type="text/javascript" src="<c:url value='/resource/bszx/'/>"></script>
  <script type="text/javascript" src="<c:url value='/resource/bszx/alipay/amui-demo_files/amui.js'/>"></script>
</head>
<body>
<div data-role="page">
  <div data-role="content" style="background-color:#EFEFF4;padding-top:15px;">
    <div class="am-list-body">
      <!--<div class="am-search am-input-autoclear">
          <div class="am-search-input">
              <div class="am-search-icon"><i class="am-icon" am-mode="search"></i></div>
              <input class="am-search-value" type="text" id="keyword" placeholder="搜索" value="">
              <div class="am-search-clear"><i class="am-icon-clear am-icon" am-mode="clear clear-tiny"></i></div>
          </div>
          <div class="am-search-button">
              <button type="button" class="am-button" am-mode="little blue" disabled="disabled" onclick="SearchQuestion()">确定</button>
          </div>
      </div>-->
    </div>
    <div class="am-card" style="padding-top:10px">
      <div id="Questions"></div>
    </div>
  </div>
</div>
<div style="padding-left:15px;padding-right:15px;margin-top:15PX;margin-bottom:20px;">
  <button class="am-button am-button-light" id="moreButton" style="visibility:visible;">更多</button>
</div>
<script type="text/javascript">
  $(function () {
    $("#toast").show();
    search();
    $("#moreButton").click(function () {
      page_index++;
      search();
    });
  });
  function getCookie(key) {
    var keyValues = document.cookie.split(";");
    for (var index = 0; index < keyValues.length; index++) {
      var keyValue = keyValues[index].split("=");
      if (keyValue[0].trim() == key)
        return keyValue[1];
    }
    return null;
  }
  function SearchQuestion() {
    $("#Questions").html("");
    search();
    $("#moreButton").click(function () {
      page_index++;
      search();
    });
  }
  var page_index = 1;
  function search() {
    var userid = ${member.guid};
    var url = "<c:url value='/api/matters/page/consult?page_size=10&page_index='/>"+page_index+"&user_id="+userid;
    $.ajax(url, {
      type: "get",
      success: function (msg) {
        if (msg["succ"] == "True") {
          var total = parseInt(msg["data"].totals);
          if (total > 0) {
            addTolist(msg["data"].list);
            if (total > page_index) {
              $("#moreButton").css("visibility", "visible");
            }
            else {
              $("#moreButton").css("visibility", "hidden");
            }
          }
        }
        else {
          alert("你还没有进行咨询过");
          location.href = "<c:url value='/weixin/wx_member/bszx/index'/>";
        }
      },
      error: function () { },
      complete: function () {
        $("#toast").hide();
      }
    });
  }
  function addTolist(result) {
    var content = "";
    for (var i = 0; i < result.length; i++) {
      var temp = result[i].context;
      //alert(result[i].CreateTime);
      content +=
              '<div class="am-card" onclick="Answer(result[i].Guid)">' +
              '<div class="am-card-item">' +
              '<div class="am-card-item-header">' +
              ' <h3 class="am-card-item-title" id="title">' + result[i].context + '</h3>' +
              '<div class="am-card-item-footnote">' +
              '<div class="am-card-item-tims  am-ft-right">' + result[i].CreateTime + '</div>' +
              '</div>' +
              '</div>' +
              '<div class="am-card-item-content">' +
              ' <div class="am-card-item-subject">' +
              '  <br />' +
              '  <p class="am-ft-orange" style="word-break:break-all" id="' + result[i].Guid + '"></p>' +
              '  <br />' +
              ' </div>' +
              ' </div>' +
              '</div>' +
              ' </div>';
    }
    $("#Questions").append(content);
  }


  function Answer(Guid) {
    //var cs = "." + Guid;
    var url = "../../CityService.Service/PoliceService.svc/GetAnswer";
    $.ajax(url, {
      type: "get",
      data: {
        Guid: Guid,
      },
      success: function (msg) {
        if (msg.d.succ == "True") {
          var result = msg.d.data.Context;
          $("#" + Guid + "").css("display", "");
          $("#" + Guid + "").append(result);
        }
        else {
          var result = "暂时未回复你的问题，请稍后再查询";
          return result;
        }
      },
      error: function () { }
    });
  }
</script>
</body>
</html>
